package guoanmaker.operator.business.controller;

import guoanmaker.operator.business.model.OperatorCities;
import guoanmaker.operator.business.service.OperatorCitiesServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 *  
 *
 * @author huZhaoyu 
 * @ClassName: OperatorCitiesController
 * @Description: OperatorCitiesController 
 * @date 2017/7/12 上午10:11 
 */
@RestController
@RequestMapping(ApiController.OPERATOR_CITIES)
public class OperatorCitiesController {
    private final AjaxJson ajaxJson;
    private final OperatorCitiesServiceInterface operatorCitiesServiceInterface;

    public OperatorCitiesController(AjaxJson ajaxJson, OperatorCitiesServiceInterface operatorCitiesServiceInterface) {
        this.ajaxJson = ajaxJson;
        this.operatorCitiesServiceInterface = operatorCitiesServiceInterface;
    }

    /** 
    * @Title: saveCities
    * @Description: 新增/修改城市 
    * @param: OperatorCities   
    * @return AjaxJson    
    * @throws 
    */
    @ApiOperation(value = "保存城市", notes = "新增/修改城市")
    @PostMapping(value = "saveCities")
    public AjaxJson saveCities(@RequestBody OperatorCities operatorCities) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorCitiesServiceInterface.saveCities(operatorCities));
    }

    /** 
     * @Title: deleteCitiesById
     * @Description: 根据Id删除城市
     * @param: String id  
     * @return AjaxJson 
     * @throws 
     */
    @ApiOperation(value = "删除城市", notes = "根据Id删除城市")
    @DeleteMapping(value = "delete/{id}")
    public AjaxJson deleteCitiesById(@PathVariable(value = "id") String id) {
        operatorCitiesServiceInterface.deleteCitiesById(id);
        return ajaxJson.setSuccess(true).setStatus(200).setData("数据删除成功!");
    }

    /**
     * @return OperatorCities    
     * @Title: getCitiesById 
     * @Description: 根据Id查询城市
     * @param: String id   
     * @throws 
     */
    @ApiOperation(value = "根据Id查询城市", notes = "根据Id查询城市")
    @GetMapping(value = "getCitiesById")
    public AjaxJson getCitiesById(@RequestParam(value = "id") String id) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorCitiesServiceInterface.getCitiesById(id));
    }

    /**
     * @return AjaxJson   
     * @Title: getAllCities
     * @Description: 查找所有城市 
     * @throws 
     */
    @ApiOperation(value = "查找所有城市", notes = "查找所有城市")
    @GetMapping(value = "getAllCities")
    public AjaxJson getAllCities() {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorCitiesServiceInterface.getAllCities());
    }

    /**
     * @return AjaxJson   
     * @Title: getAllCitiesByPage 
     * @Description: 查询所有城市并分页
     * @param: Integer page 页码
     * @param: Integer size 条数
     * @throws 
     */
    @ApiOperation(value = "分页查询城市", notes = "分页查询城市")
    @GetMapping(value = "getAllCitiesByPage")
    public AjaxJson getAllCitiesByPage(@RequestParam(value = "page", defaultValue = "0") Integer page,
                                           @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorCitiesServiceInterface.getAllCitiesByPage(page, size));
    }

    /**
     * @return AjaxJson   
     * @Title: getCitiesByProvince 
     * @Description: 根据省份查询城市
     * @param: String provinceCode 省份识别码
     */
    @ApiOperation(value = "根据省份查询城市", notes = "根据省份查询城市")
    @GetMapping(value = "getCitiesByProvince")
    public AjaxJson getCitiesByProvince(@RequestParam(value = "provinceCode") String provinceCode) {
        return ajaxJson.setSuccess(true).setStatus(200).setData(operatorCitiesServiceInterface.getAllCitiesByProvinceCode(provinceCode)).setMsg("请求成功");
    }

}
